package user

import (
	"MembershipRegist/db"
	"MembershipRegist/models"
)

func (c *Controller) ActivityCommentInsert() {
	activityID, err := c.GetInt("activity_id")
	if err != nil {
		c.ResponseFailed(201, "activity_id 不合法")
		return
	}

	comment := c.GetString("comment")
	if comment == "" {
		c.ResponseFailed(202, "评论内容不能为空")
		return
	}

	commentValue := models.OrganizationActivityComment{
		OrganizationActivityID: uint(activityID),
		UserID:                 c.UserID,
		Comment:                comment,
		OrganizationAdminID:    0,
	}

	if value := db.DB.Create(&commentValue); value.Error != nil {
		c.ResponseFailed(203, "评论失败")
		return
	}

	c.ResponseSuccess()
}

func (c *Controller) ActivityCommentDelete() {
	commentID, err := c.GetInt("comment_id")
	if err != nil {
		c.ResponseFailed(201, "comment_id 不合法")
		return
	}

	db.DB.Delete(&models.OrganizationActivityComment{}, "id = ? and user_id = ?", commentID, c.UserID)

	c.ResponseSuccess()
}
